package com.example.blogapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.blogapi.domain.MsArticle;
import com.example.blogapi.mapper.MsArticleMapper;
import com.example.blogapi.service.ThreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class ThreadServiceImpl implements ThreadService  {
    @Autowired
    MsArticleMapper articleMapper;
    @Override
    @Async("taskExecutor")
    public void updateArticleViewCount(MsArticle article) {
        LambdaUpdateWrapper<MsArticle> updateWrapper = new LambdaUpdateWrapper<>();
        article.setViewCounts(article.getViewCounts()+1);
        updateWrapper.eq(MsArticle::getId,article.getId());
        articleMapper.update(article,updateWrapper);
    }
}
